package singleton;

/**
 * @Author：LJ
 * @Description：单例模式
 * @Date: 2017/11/24
 * @Modified By:
 */
public class Emperor {

    public final static Emperor emperor = new Emperor();//注意这里的final 还可以解决线程安全

    //限制产生多个对象
    private Emperor() {
    }

    //通过该方法获取实例对象
    public static Emperor getInstance() {
        return emperor;
    }

    //类中其他方法,尽量是static
    public static void say() {
        System.out.println("有事启奏,无事退朝");
    }


    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            Emperor emperor = Emperor.getInstance();
            emperor.say();
        }
    }
}
